
import java.util.Scanner;
public class main_209 {



        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);

            System.out.print("请输入目标值 s: ");
            int s = scanner.nextInt();

            System.out.print("请输入 nums 数组的长度: ");
            int n = scanner.nextInt();


            int[] nums = new int[n];
            System.out.println("请输入 nums 数组的元素: ");
            for (int i = 0; i < n; i++) {
                nums[i] = scanner.nextInt();
            }

            int result = minSubArrayLen(s, nums);
            System.out.println("满足条件的最小子数组长度是: " + result);

            scanner.close();
        }

        public static int minSubArrayLen(int s, int[] nums) {
            int min = Integer.MAX_VALUE;
            for (int i = 0; i < nums.length; i++) {
                int sum = nums[i];
                if (sum >= s)
                    return 1;
                for (int j = i + 1; j < nums.length; j++) {
                    sum += nums[j];
                    if (sum >= s) {
                        min = Math.min(min, j - i + 1);
                        break;
                    }
                }
            }
            return min == Integer.MAX_VALUE ? 0 : min;
        }
    }

